import { Message, Middleware } from 'mirai-js'
import { Bot as BotType } from 'mirai-js/dist/node/index'
import jsonfile from 'jsonfile'
import appConfig from '../../config/app.config'
import { helpTitleInfo } from '../../config/help.config'
import { textCommandFilter } from '../../middleware/textCommandFilter'
export default (bot: BotType) => {
  // 监听群消息事件
  bot.on(
    'GroupMessage',
    new textCommandFilter('help').done(async (data) => {
      const file = jsonfile.readFileSync('./src/static/help.static.json')
      let str = helpTitleInfo()
      file.forEach((item) => {
        str += `${appConfig.PREFIX}${item.command}  ${item.describe}\n`
      })

      bot.sendMessage({
        group: data.sender.group.id,
        message: new Message().addText(str),
      })
    }),
  )
}
